package dateStructure;

import java.util.Scanner;

public class sequenceStack {
    private int Maxsize=1007;
    private int date[];
    private int top;
    sequenceStack(){
        date=new int[Maxsize];
        top=-1;
    }
    private boolean push(int date){
        if(top+1==Maxsize){
            System.out.println("栈已满！");
            return false;
        }
        this.date[++top]=date;
        return true;
    }
    private boolean pop(){
        if(top==-1){
            System.out.println("栈已空！");
            return false;
        }
        int e=this.date[top--];
        return true;
    }
    public int getElem(){
        if(top==-1){
            System.out.println("栈已空！");
            System.exit(0);
        }
        return this.date[top];
    }

    public static void main(String[] args) {
        sequenceStack s=new sequenceStack();
        Scanner scanner=new Scanner(System.in);
        System.out.print("请输入元素的个数：");
        ///入栈部分
        int n=scanner.nextInt();
        int sum=n;
        while (sum-->0){
            s.push(scanner.nextInt());
        }
        ///出栈部分
        sum=n;
        System.out.println("栈中元素依次为：");
        while (sum-->0){
            System.out.println("弹出栈顶元素为："+s.getElem());
            s.pop();
        }
        System.out.println();
    }
}

